"""
生成订单用例
"""
import unittest
from common.base import get_driver
from page.home_page import HomePage
from page.phone_type_page import PhoneTypePage
from page.n85_page import N85Page
from page.settle_accounts_page import SettleAccountPage
from page.log_in_to_buy_page import LogInToBuy
from page.add_page import AddPage
from page.submit_order import SubmitOrder
from page.finish_page import Finish
from page.user_center import UserCenter


class HavePaidTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 打开浏览器
        driver = get_driver()
        cls.home = HomePage(driver)
        cls.phone_type = PhoneTypePage(driver)
        cls.n85 = N85Page(driver)
        cls.settle_account = SettleAccountPage(driver)
        cls.log_in_to_buy = LogInToBuy(driver)
        cls.add_page = AddPage(driver)
        cls.submit_order = SubmitOrder(driver)
        cls.finish = Finish(driver)
        cls.user_center = UserCenter(driver)

    def setUp(self) -> None:
        # 访问目标网址
        self.home.get('http://localhost:8080/ecshop/index.php')
        # 选择购物商品操作
        self.home.click_phone_type()
        self.phone_type.click_n85()
        self.n85.click_buy()
        self.settle_account.click_settle_accounts()

    # def tearDown(self) -> None:
    #     # 再次访问目标网址
    #     self.home.get('http://localhost:8080/ecshop/index.php')

    def test01_generate_order_unpaid(self):
        # 第一次购物请登录
        self.log_in_to_buy.userinfo(user="root123456", password="root123456")
        self.add_page.click_add()
        # 生成已支付订单操作
        self.submit_order.click_balance()
        self.submit_order.click_boutique()
        self.submit_order.click_wish()
        self.submit_order.click_bill()
        self.submit_order.click_bill_type()
        self.submit_order.send_keys_remark("尽快发货")
        self.submit_order.click_submit()
        # 获取订单状态
        self.finish.click_user()
        self.user_center.click_indent()
        order_state = self.user_center.order_status()

        # 断言 最新订单状态为未确认,未付款,未发货
        self.assertEqual(order_state, '已确认,已付款,未发货', msg="已支付用例未通过")

    def test02_generate_order_paid(self):
        # 生成未支付订单操作
        self.submit_order.click_bank_transfer()
        self.submit_order.click_boutique()
        self.submit_order.click_wish()
        self.submit_order.click_bill()
        self.submit_order.click_bill_type()
        self.submit_order.send_keys_remark("尽快发货")
        self.submit_order.click_submit()
        # 获取订单状态
        self.finish.click_user()
        self.user_center.click_indent()
        order_state = self.user_center.order_status()

        # 断言 最新订单状态为未确认,未付款,未发货
        self.assertEqual(order_state, '未确认,未付款,未发货', msg="未支付用例未通过")

    @classmethod
    def tearDownClass(cls) -> None:
        # 关闭浏览器
        cls.home.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
